package org.ricks.gateway.cluster.transport;

import io.scalecube.cluster.transport.api.Message;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class MessageBuilder {
    private String sender;
    private Map<String, String> headers = new HashMap<>();
    private Object data;


    public static Message from(Message source) {
        return Message.withData(source.data())
                .qualifier(source.qualifier())
                .correlationId(source.correlationId())
                .build();
    }

    public MessageBuilder sender(String sender) {
        this.sender = sender;
        return this;
    }

    public MessageBuilder header(String key, String value) {
        this.headers.put(key, value);
        return this;
    }

    public MessageBuilder headers(Map<String, String> headers) {
        this.headers.putAll(headers);
        return this;
    }

    public MessageBuilder data(Object data) {
        this.data = data;
        return this;
    }

    public Message build() {
        return Message.builder()
                .sender(sender)
                .headers(Collections.unmodifiableMap(headers))
                .data(data)
                .build();
    }
}

